﻿@page "/CodeGeneration/Index"
@inherits IndexComponentBase<FieldsView>
<div>
    <Steps Current="current">
        @foreach (var item in steps)
        {
            <Step Title="@item.Title" Subtitle="@item.Content" />
        }
    </Steps>
    <div class="steps-action">
        <Space>
            <SpaceItem>
                @if (current > 0 && current < steps.Length - 1)
                {
                    <Button Type="@ButtonType.Primary" OnClick="OnPreClick">@LanguageService[$"{CurrencyConstant.Page}.{CurrencyConstant.Back}"]</Button>
                }
            </SpaceItem>
            <SpaceItem>
                @if (current < steps.Length - 2 && current > 0)
                {
                    <Button Type="@ButtonType.Primary" OnClick="OnNextClick">@LanguageService[$"{CurrencyConstant.Page}.{CurrencyConstant.Next}"]</Button>
                }
            </SpaceItem>
            <SpaceItem>
                @if (current == steps.Length - 2)
                {
                    <Button Type="@ButtonType.Primary" Danger OnClick=@(() => { OnGenerateClick(); })>
                        @LanguageService[$"{CurrencyConstant.Page}.{CurrencyConstant.Generate}"]
                    </Button>
                }

            </SpaceItem>
        </Space>



    </div>
    <div class="steps-content">
        @switch (current)
        {
            case 0:
                <CavTableTemplate TData="FieldsView"
                          RowCallback="RowCallback"
                          TableOptions="TableOptions">
                    </CavTableTemplate>
                break;
            case 1:
                <div style="margin-bottom:16px;margin-top:16px;">
                    <Form Model="@GenerateData" @ref="GenerateFrom">
                        <Space Direction="DirectionVHType.Vertical" Size="@("large")">
                            <FormItem>
                                <Text>
                                    @context.EntitieName
                                </Text>
                            </FormItem>
                            <FormItem Label="@LanguageService[$"{CurrencyConstant.Page}.{CurrencyConstant.GenerateContent}"]">
                                <Checkbox @bind-Value="@context.IsGenerateController">@LanguageService[$"{CurrencyConstant.Page}.{CurrencyConstant.Controller}"]</Checkbox>
                                <Checkbox @bind-Value="@context.IsGenerateIndex">@LanguageService[$"{CurrencyConstant.Page}.{CurrencyConstant.ListPage}"]</Checkbox>
                                <Checkbox @bind-Value="@context.IsGenerateDataTemplate">@LanguageService[$"{CurrencyConstant.Page}.{CurrencyConstant.DataTemplatePage}"]</Checkbox>
                                <Checkbox @bind-Value="@context.IsGenerateViewModel">@LanguageService[$"{CurrencyConstant.Page}.{CurrencyConstant.PageModel}"]</Checkbox>
                            </FormItem>
                            <FormItem Label="@LanguageService[$"{CurrencyConstant.Page}.{CurrencyConstant.IsCover}"]">
                                <Switch @bind-Value="@context.IsCover" />
                            </FormItem>
                        </Space>

                    </Form>
                </div>
                break;
            case 2:
                <Tabs DefaultActiveKey="1" @bind-ActiveKey="@nKey">
                    @foreach (var item in lstTabs)
                    {
                        <TabPane Key="@item.KeyName" Tab="@item.TabName">
                            <ChildContent>
                                <CavHighlightedCode Code="@item.Content" Language="csharp"></CavHighlightedCode>
                            </ChildContent>
                        </TabPane>
                    }
                </Tabs>
                break;
            case 3:
                <Result Status="@ResultStatus"
                        Title="@ReusltTitle"
                        SubTitle="@ResultSubTitle">
                    <Extra>
                        <Button Type="@ButtonType.Primary" OnClick='()=> { NavigationManager.NavigateTo("/"); }'>@LanguageService[$"{CurrencyConstant.Page}.{CurrencyConstant.ReturnHome}"]</Button>
                        <Button OnClick='()=> { current = 0; }'>@LanguageService[$"{CurrencyConstant.Page}.{CurrencyConstant.ContinueGeneration}"]</Button>
                    </Extra>

                </Result>
                break;
            default:
                break;
        }
    </div>

</div>

<style>
    .steps-content {
        margin-top: 16px;
        border: 3px dashed #e9e9e9;
        border-radius: 6px;
        text-align: center;
        background:@Layout.White;
        
    }

    .steps-action {
        margin-top: 24px;
    }
</style>

@code {
    public class StepItem
    {
        public string Title { get; set; }
        public string Content { get; set; }
    }

    public int current { get; set; } = 0;
}